<template>
  <div>
    <city-header></city-header>
    <city-search :citys="cities"></city-search>
    <city-list :hotList="hotCities" :citys="cities" :letter="letter"></city-list>
    <city-alphabet :citys="cities" @change="handleLetterChange"></city-alphabet>
  </div>
</template>

<script>
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
import axios from 'axios'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data: () => {
    return {
      hotCities: [],
      cities: {},
      letter: ''
    }
  },
  methods: {
    getCityInfo: async function () {
      const data = await axios.get('/api/city.json')
      this.getCityInfoSusses(data)
    },
    getCityInfoSusses: function (res) {
      const data = res.data
      if (data.data && data.ret) {
        this.hotCities = data.data.hotCities
        this.cities = data.data.cities
      }
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>

<style lang="stylus" scoped>

</style>
